package com.bnyy.medicalHousekeeper.moudle.message.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bnyy.medicalHousekeeper.DialogHelper;
import com.bnyy.medicalHousekeeper.R;
import com.bnyy.medicalHousekeeper.base.BaseActivityImpl;
import com.bnyy.medicalHousekeeper.moudle.message.MessageManager;
import com.bnyy.medicalHousekeeper.moudle.message.adapter.ChatAdapter;
import com.bnyy.message.bean.chat.Chat;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/12/3
 **/
public class StrangerChatsActivity extends BaseActivityImpl {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.iv_no_data)
    ImageView ivNoData;
    @BindView(R.id.tv_no_data)
    TextView tvNoData;
    @BindView(R.id.ll_no_data)
    LinearLayout llNoData;

    private ChatAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.layout_recycler_view;
    }

    @Override
    public String getTitleStr() {
        return "陌生人消息";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView tv = new TextView(mContext);
        tv.setTextAppearance(R.style.NormalTextView);
        tv.setText("全部已读");
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogHelper.showNormalDialog(mContext, "确认要清除所有未读消息吗？",
                        new DialogHelper.Callback() {
                            @Override
                            public void onRightClick(AlertDialog alertDialog) {
                                super.onRightClick(alertDialog);

                                ArrayList<Chat> chats = adapter.getDatas();

                                for (Chat chat : chats) {
                                    MessageManager.clearUnreadCount(chat);
                                }
                                refresh();
                            }
                        });
            }
        });

        setOptions(tv);

        recyclerView.setBackgroundColor(Color.WHITE);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));

        adapter = new ChatAdapter(mContext, new ChatAdapter.Callback() {
            @Override
            public void onItemClick(Chat chat) {
                ChatMessageActivity.show(mContext, chat);
            }

            @Override
            public void topping(Chat chat) {

            }

            @Override
            public void delete(Chat chat) {

            }

            @Override
            public void noDisturb(Chat chat) {

            }
        });

        recyclerView.setAdapter(adapter);

    }

    @Override
    protected void onResume() {
        super.onResume();
        refresh();
    }

    private void refresh() {
        adapter.refresh(MessageManager.getStrangerChats());
    }
}




































